<?php
require_once('internal/IModule.interface.php');

class Modules implements IModule {
	public $sections;
	function __construct($engine=null) {
		global $lang;
		$this->sections = array(
			$lang['install'] => '#',
			$lang['options'] => '#',
			$lang['delete'] => '#'
		);
		$this->engine = $engine;
	}
	function execute() {
		global $db;
		?>
		<div id="list">
		<table cellpadding="0" cellspacing="0" border="0">
			<?php
				$com = $this->readModTypes();
				$modtypes = $com[0];
				$modfull = $com[1];
				for ($i=0; $i<count($modtypes); $i++) {
					$sh = '';
					$db->modeAssoc();
					$res = $db->select('modules', '*', array("type='{$modtypes[$i]}'"));
					echo '<tr class="head"><td colspan="4" class="desc">'.$modfull[$i]."</td></tr>\n";
					if ($db->num_rows > 0) {
						foreach ($res as $k => $ass) {
							print '<tr'.$sh.'>
								<td style="width: 260px">'.$ass['fullname'].'</td>
								<td style="width: 80px">'.$ass['version'].'</td>
								<td style="width: 180px">'.$ass['author'].'</td>
								<td>'.$ass['description'].'</td>
							</tr>';
							$sh = ($sh=="") ? ' class="shaded"' : '';
						}
					} else echo '<tr><td colspan="4" class="nonefound desc">No modules found</td></tr>';
				}
			?>
		</table>
		</div>
	<?php
	}
	private function readModTypes() {
		global $lang;
		$xml = simplexml_load_file('internal/modulepaths.xml');
		$modtypes = array();
		$modfull = array();

		foreach($xml->module as $module) {
			$l = (string) $module->type;
			array_push($modtypes, $l);
			array_push($modfull, $lang['modtypes'][$l]);
		}

		$combine = array($modtypes, $modfull);
		return $combine;
	}
}
?>
